package net.csdn.business.discuss.api.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.csdn.business.discuss.api.model.dto.SyncDeleteDTO;
import net.csdn.business.discuss.api.model.entity.DiscussComment;
import net.csdn.business.discuss.api.model.query.DiscussCommentQuery;
import net.csdn.business.discuss.api.model.vo.DiscussCommentVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @ClassName DiscussCommentMapper
 * @Description 讨论评论Mapper接口
 * @Author zhangyl
 * @Date 2023/7/18 11:16
 */
public interface DiscussCommentMapper extends BaseMapper<DiscussComment>
{

    /**
     * 分页查询讨论评论列表
     *
     * @param query 字典类型信息
     * @return 字典类型集合信息
     */
    @Select("<script> select t1.object_id,t1.serial_number,t1.content,t1.md_content,t1.is_hide,t1.reply_total+1 as reply_total,t1.like_total,t1.is_remark,t1.is_deleted,t1.ip,t1.created_by,t1.created_date FROM discuss_comment t1  " +
            " where t1.discuss_id = #{query.discussId} and t1.type=1 " +
            " order by t1.serial_number asc " +
            "</script>")
    public List<DiscussCommentVO> findPageList(Page page, @Param("query") DiscussCommentQuery query);

    /**
     * 分页查询讨论评论的回复列表
     *
     * @param query 字典类型信息
     * @return 字典类型集合信息
     */
    @Select("<script> select t1.object_id,t1.serial_number,t1.content,t1.md_content,t1.is_hide,t1.reply_total+1 as reply_total,t1.like_total,t1.is_remark,t1.is_deleted,t1.ip,t1.created_by,t1.created_date FROM discuss_comment t1  " +
            " where t1.parent_id = #{query.parentId} and t1.type=2 " +
            " order by t1.serial_number asc " +
            "</script>")
    public List<DiscussCommentVO> findReplyPageList(Page page, @Param("query") DiscussCommentQuery query);

    /**
     * 查询讨论评论
     * 
     * @param id 讨论评论主键
     * @return 讨论评论
     */
    @Select("select id ,object_id ,discuss_id,source_id,source_type,content,md_content,parent_id ,serial_number,ip,type,audit_status,is_hide ,reply_total+1 as reply_total,like_total,is_remark,is_deleted,created_by,created_date,last_modified_by,last_modified_date from discuss_comment where object_id=#{id}")
    public DiscussCommentVO selectDiscussCommentById(@Param("id")String id);

    /**
     * 查询讨论评论列表
     * 
     * @param query 讨论评论
     * @return 讨论评论集合
     */
    public List<DiscussCommentVO> selectDiscussCommentList(@Param("query") DiscussCommentQuery query);


    @Update("update discuss_comment set reply_total=reply_total+#{sum} where object_id=#{id}")
    public Integer updateReplyTotal(@Param("id")String id, @Param("sum")Integer sum);

    @Update("update discuss_comment set like_total=like_total+#{sum} where object_id=#{id}")
    public Integer updateLikeTotal(@Param("id")String id, @Param("sum")Integer sum);

    /**
     * 删除讨论评论
     *
     * @param params 请求参数
     * @return 结果
     */
    @Delete("delete from discuss_comment where source_id = #{params.sourceId}")
    public Integer syncDelete(@Param("params") SyncDeleteDTO params);

}
